﻿using System;
using System.Data;
using System.Data.SqlClient;
using APP.HELPER.Data.Helper;
using APP.HELPER.Utils.CustomizeToolbox;
using DevExpress.XtraEditors;
using ComboBox = System.Windows.Forms.ComboBox;

namespace Dictionary.ERP
{
    public class DIC_SALARY_RANK
    {
        private string m_Description;
        private string m_RankCode;
        private string m_RankName;

        public DIC_SALARY_RANK()
        {
            m_RankCode = "";
            m_RankName = "";
            m_Description = "";
        }

        public DIC_SALARY_RANK(string RankCode, string RankName, string Description)
        {
            m_RankCode = RankCode;
            m_RankName = RankName;
            m_Description = Description;
        }

        public string Description
        {
            get { return m_Description; }
            set { m_Description = value; }
        }

        public string ProductName
        {
            get { return "Class DIC_SALARY_RANK"; }
        }

        public string ProductVersion
        {
            get { return "1.0.0.0"; }
        }

        public string RankCode
        {
            get { return m_RankCode; }
            set { m_RankCode = value; }
        }

        public string RankName
        {
            get { return m_RankName; }
            set { m_RankName = value; }
        }

        public void AddCombo(ComboBox combo)
        {
            GridCalendarControlLib.TableToComboBox(combo, GetList(), "RankName", "RankCode");
        }

        public void AddComboAll(ComboBox combo)
        {
            var list = new DataTable();
            list = GetList();
            DataRow row = list.NewRow();
            row["RankCode"] = "All";
            row["RankName"] = "Tất cả";
            list.Rows.InsertAt(row, 0);
            GridCalendarControlLib.TableToComboBox(combo, list, "RankName", "RankCode");
        }

        public void AddComboEdit(ComboBoxEdit combo)
        {
            var list = new DataTable();
            list = GetList();
            foreach (DataRow row in list.Rows)
            {
                combo.Properties.Items.Add(row["RankName"]);
            }
        }

        public void AddGridLookupEdit(GridLookUpEdit gridlookup)
        {
            var list = new DataTable();
            list = GetList();
            gridlookup.Properties.DataSource = list;
            gridlookup.Properties.DisplayMember = "RankName";
            gridlookup.Properties.ValueMember = "RankCode";
        }

        public string Delete()
        {
            string[] myParams = {"@RankCode"};
            object[] myValues = {m_RankCode};
            var helper = new SqlHelper();
            return helper.ExecuteNonQuery("DIC_SALARY_RANK_Delete", myParams, myValues);
        }

        public string Delete(string RankCode)
        {
            string[] myParams = {"@RankCode"};
            object[] myValues = {RankCode};
            var helper = new SqlHelper();
            return helper.ExecuteNonQuery("DIC_SALARY_RANK_Delete", myParams, myValues);
        }

        public string Delete(SqlConnection myConnection, string RankCode)
        {
            string[] myParams = {"@RankCode"};
            object[] myValues = {RankCode};
            var helper = new SqlHelper();
            return helper.ExecuteNonQuery(myConnection, "DIC_SALARY_RANK_Delete", myParams, myValues);
        }

        public string Delete(SqlTransaction myTransaction, string RankCode)
        {
            string[] myParams = {"@RankCode"};
            object[] myValues = {RankCode};
            var helper = new SqlHelper();
            return helper.ExecuteNonQuery(myTransaction, "DIC_SALARY_RANK_Delete", myParams, myValues);
        }

        public bool Exist(string RankCode)
        {
            bool hasRows = false;
            string[] myParams = {"@RankCode"};
            object[] myValues = {RankCode};
            var helper = new SqlHelper();
            SqlDataReader reader = helper.ExecuteReader("DIC_SALARY_RANK_Get", myParams, myValues);
            if (reader != null)
            {
                hasRows = reader.HasRows;
                reader.Close();
                helper.Close();
                reader = null;
            }
            return hasRows;
        }

        public string Get(string RankCode)
        {
            string str = "";
            string[] myParams = {"@RankCode"};
            object[] myValues = {RankCode};
            var helper = new SqlHelper();
            SqlDataReader reader = helper.ExecuteReader("DIC_SALARY_RANK_Get", myParams, myValues);
            if (reader != null)
            {
                while (reader.Read())
                {
                    m_RankCode = Convert.ToString(reader["RankCode"]);
                    m_RankName = Convert.ToString(reader["RankName"]);
                    m_Description = Convert.ToString(reader["Description"]);
                    str = "OK";
                }
                reader.Close();
                helper.Close();
                reader = null;
            }
            return str;
        }

        public string Get(SqlConnection myConnection, string RankCode)
        {
            string str = "";
            string[] myParams = {"@RankCode"};
            object[] myValues = {RankCode};
            var helper = new SqlHelper();
            SqlDataReader reader = helper.ExecuteReader(myConnection, "DIC_SALARY_RANK_Get", myParams, myValues);
            if (reader != null)
            {
                while (reader.Read())
                {
                    m_RankCode = Convert.ToString(reader["RankCode"]);
                    m_RankName = Convert.ToString(reader["RankName"]);
                    m_Description = Convert.ToString(reader["Description"]);
                    str = "OK";
                }
                reader.Close();
                helper.Close();
                reader = null;
            }
            return str;
        }

        public string Get(SqlTransaction myTransaction, string RankCode)
        {
            string str = "";
            string[] myParams = {"@RankCode"};
            object[] myValues = {RankCode};
            var helper = new SqlHelper();
            SqlDataReader reader = helper.ExecuteReader(myTransaction, "DIC_SALARY_RANK_Get", myParams, myValues);
            if (reader != null)
            {
                while (reader.Read())
                {
                    m_RankCode = Convert.ToString(reader["RankCode"]);
                    m_RankName = Convert.ToString(reader["RankName"]);
                    m_Description = Convert.ToString(reader["Description"]);
                    str = "OK";
                }
                reader.Close();
                helper.Close();
                reader = null;
            }
            return str;
        }

        public DataTable GetList()
        {
            var helper = new SqlHelper();
            return helper.ExecuteDataTable("DIC_SALARY_RANK_GetList");
        }

        public string Insert()
        {
            string[] myParams = {"@RankCode", "@RankName", "@Description"};
            object[] myValues = {m_RankCode, m_RankName, m_Description};
            var helper = new SqlHelper();
            return helper.ExecuteNonQuery("DIC_SALARY_RANK_Insert", myParams, myValues);
        }

        public string Insert(SqlTransaction myTransaction)
        {
            string[] myParams = {"@RankCode", "@RankName", "@Description"};
            object[] myValues = {m_RankCode, m_RankName, m_Description};
            var helper = new SqlHelper();
            return helper.ExecuteNonQuery(myTransaction, "DIC_SALARY_RANK_Insert", myParams, myValues);
        }

        public string Insert(string RankCode, string RankName, string Description)
        {
            string[] myParams = {"@RankCode", "@RankName", "@Description"};
            object[] myValues = {RankCode, RankName, Description};
            var helper = new SqlHelper();
            return helper.ExecuteNonQuery("DIC_SALARY_RANK_Insert", myParams, myValues);
        }

        public string Insert(SqlConnection myConnection, string RankCode, string RankName, string Description)
        {
            string[] myParams = {"@RankCode", "@RankName", "@Description"};
            object[] myValues = {RankCode, RankName, Description};
            var helper = new SqlHelper();
            return helper.ExecuteNonQuery(myConnection, "DIC_SALARY_RANK_Insert", myParams, myValues);
        }

        public string Insert(SqlTransaction myTransaction, string RankCode, string RankName, string Description)
        {
            string[] myParams = {"@RankCode", "@RankName", "@Description"};
            object[] myValues = {RankCode, RankName, Description};
            var helper = new SqlHelper();
            return helper.ExecuteNonQuery(myTransaction, "DIC_SALARY_RANK_Insert", myParams, myValues);
        }

        public string NewID()
        {
            return SqlHelper.GenCode("DIC_SALARY_RANK", "RankCode", "NL");
        }

        public string Update()
        {
            string[] myParams = {"@RankCode", "@RankName", "@Description"};
            object[] myValues = {m_RankCode, m_RankName, m_Description};
            var helper = new SqlHelper();
            return helper.ExecuteNonQuery("DIC_SALARY_RANK_Update", myParams, myValues);
        }

        public string Update(string RankCode, string RankName, string Description)
        {
            string[] myParams = {"@RankCode", "@RankName", "@Description"};
            object[] myValues = {RankCode, RankName, Description};
            var helper = new SqlHelper();
            return helper.ExecuteNonQuery("DIC_SALARY_RANK_Update", myParams, myValues);
        }

        public string Update(SqlConnection myConnection, string RankCode, string RankName, string Description)
        {
            string[] myParams = {"@RankCode", "@RankName", "@Description"};
            object[] myValues = {RankCode, RankName, Description};
            var helper = new SqlHelper();
            return helper.ExecuteNonQuery(myConnection, "DIC_SALARY_RANK_Update", myParams, myValues);
        }

        public string Update(SqlTransaction myTransaction, string RankCode, string RankName, string Description)
        {
            string[] myParams = {"@RankCode", "@RankName", "@Description"};
            object[] myValues = {RankCode, RankName, Description};
            var helper = new SqlHelper();
            return helper.ExecuteNonQuery(myTransaction, "DIC_SALARY_RANK_Update", myParams, myValues);
        }
    }
}